package com.fzzz.kotlindemo

import android.os.Bundle
import android.support.v7.app.AppCompatActivity
import android.view.Gravity
import android.widget.LinearLayout
import org.jetbrains.anko.*
import org.jetbrains.anko.sdk25.coroutines.onClick

/**
 * Created by Shen Chao
 * Created by 2019-01-09
 */
class AnkoActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        linearLayout {
            orientation = LinearLayout.VERTICAL

            textView("hello") {
                textSize = 14f
            }.lparams(width = wrapContent, height = wrapContent) {
                gravity = Gravity.CENTER_HORIZONTAL
            }
            textView("I'm") {
                textColor = R.color.yellow
                textSize = 16f
            }.lparams(width = wrapContent, height = wrapContent) {
                gravity = Gravity.CENTER_HORIZONTAL
            }
            textView("Anko") {
                textColor = R.color.blue
                textSize = 18f
            }.lparams(width = wrapContent, height = wrapContent) {
                gravity = Gravity.CENTER_HORIZONTAL
            }
            textView("DSL") {
                textColor = R.color.green
                textSize = 20f
            }.lparams(width = wrapContent, height = wrapContent) {
                gravity = Gravity.CENTER_HORIZONTAL
            }
            button("yes") {
                backgroundResource = R.color.blue
                textSize = sp(20).toFloat()
                onClick {
                    toast("clicked")
                }
            }.lparams(width = matchParent, height = wrapContent)
        }
    }
}